function PlotCR3BPSunEarth(t,S,u)

r12 = 1.496*10^8;
%[km]Distance between the Sun and the Earth.

Re = 6378.136 / r12;
%[]Normalized mean equatorial radius of the Earth.

Rs = 696340 / r12;
%[]Normalized mean equatorial radius of the Moon.

[xe,ye,ze] = ellipsoid(1-u,0,0,Re,Re,Re,100);
%[]Coordinates for the Earth.

[xs,ys,zs] = ellipsoid(-u,0,0,Rs,Rs,Rs,100);
%[]Coordinates for the Earth.

Rsat = S(1:3,:);
%[]Satellite positions WRT the CM in ECI coordinates.

[L1, L2, L3, L4, L5]=librationPoints(u);

Earth = imread('Earth.bmp');
%[]Loads the image of the Earth.

ScreenSize = get(0,'ScreenSize');
%[]Determines the location and dimensions of the current monitor.

Window = figure( ...
    'Color','w', ...
    'Name','CIRCULAR RESTRICTED THREE-BODY PROBLEM', ...
    'NumberTitle','Off', ...
    'OuterPosition',ScreenSize);
%[]Opens a new window and adjusts its properties.
n = size(Rsat,2);
%[]Number of points that will be plotted.
rsat = zeros(1,n);
%[]Allocates memory for the range vector.
for k = 1:n
    
    rsat(k) = norm(Rsat(:,k));
    %[Earth radii]Current range.
    
end
a = max(rsat);
if a < 1.2
    Extent = 1.2;
else
    Extent = ceil(max(rsat));
end
%[]Axes extents.

Axes = axes(...
'CameraPosition',Extent*[0,0,1], ...
    'FontName','Arial', ...
    'FontSize',12, ...
    'FontWeight','Bold', ...
    'NextPlot','Add', ...
    'Parent',Window, ...
    'PlotBoxAspectRatio',[1,1,1], ...
    'XGrid','On', ...
    'YGrid','On', ...
    'ZGrid','On',...
    'XLim',Extent*[-1,1], ...
    'YLim',Extent*[-1,1], ...
    'ZLim',Extent*[-1,1], ...
    'XTick',Extent*(-1:0.2:1), ...
    'YTick',Extent*(-1:0.2:1), ...
    'ZTick',Extent*(-1:0.2:1));
%[]Adds an axes to the specified window and adjusts its properties.

surface(xe,ye,-ze, ...
    'CData',Earth, ...
    'EdgeColor','None', ...
    'FaceColor','TextureMap', ...
    'Parent',Axes);
%[]Adds a plot to the specified axes and adjusts its properties.

surface(xs,ys,-zs, ...
    'EdgeColor','y', ...
    'FaceColor','TextureMap', ...
    'Parent',Axes);
%[]Adds a plot to the specified axes and adjusts its properties.

plot3(Rsat(1,:),Rsat(2,:),Rsat(3,:), ...
    'Color','k', ...
    'LineStyle','none', ...
    'Marker','.', ...
    'MarkerSize',8,...
    'Parent',Axes);
%[]Adds a plot to the specified window and adjusts its properties.

plot(L1(1),L1(2), ...
    'Color','k', ...
    'LineStyle','None', ...
    'Marker','.', ...
    'MarkerSize',5, ...
    'Parent',Axes);
%[]Plots the position of L1 and adjusts its properties.

plot(L2(1),L2(2), ...
    'Color','k', ...
    'LineStyle','None', ...
    'Marker','.', ...
    'MarkerSize',5, ...
    'Parent',Axes);
%[]Plots the position of L2 and adjusts its properties.

plot(L3(1),L3(2), ...
    'Color','k', ...
    'LineStyle','None', ...
    'Marker','.', ...
    'MarkerSize',5, ...
    'Parent',Axes);
%[]Plots the position of L3 and adjusts its properties.

plot(L4(1),L4(2), ...
    'Color','k', ...
    'LineStyle','None', ...
    'Marker','.', ...
    'MarkerSize',5, ...
    'Parent',Axes);
%[]Plots the position of L4 and adjusts its properties.

plot(L5(1),L5(2), ...
    'Color','k', ...
    'LineStyle','None', ...
    'Marker','.', ...
    'MarkerSize',15, ...
    'Parent',Axes);
%[]Plots the position of L5 and adjusts its properties.

title( ...
    'SATELLITE ORBIT IN THE CR3BP', ...
    'FontSize',20, ...
    'Parent',Axes);
%[]Adds a title to the specified axes and adjusts its properties.

xlabel( ...
    '\chi_x', ...
    'FontSize',16, ...
    'Parent',Axes);
%[]Adds a label to the specified x-axis and adjusts its properties.

ylabel( ...
    '\chi_y', ...
    'FontSize',16, ...
    'Parent',Axes);
%[]Adds a label to the specified y-axis and adjusts its properties.

text( ...
    'FontName','Arial', ...
    'FontSize',12, ...
    'FontWeight','Bold', ...
    'HorizontalAlignment','Center', ...
    'Parent',Axes, ...
    'Position',[L1(1),-0.1], ...
    'String','L_1');
%[]Adds a textbox to the specified axes.

text( ...
    'FontName','Arial', ...
    'FontSize',12, ...
    'FontWeight','Bold', ...
    'HorizontalAlignment','Center', ...
    'Parent',Axes, ...
    'Position',[L2(1),-0.1], ...
    'String','L_2');
%[]Adds a textbox to the specified axes.

text( ...
    'FontName','Arial', ...
    'FontSize',12, ...
    'FontWeight','Bold', ...
    'HorizontalAlignment','Center', ...
    'Parent',Axes, ...
    'Position',[L3(1),-0.1], ...
    'String','L_3');
%[]Adds a textbox to the specified axes.

text( ...
    'FontName','Arial', ...
    'FontSize',12, ...
    'FontWeight','Bold', ...
    'HorizontalAlignment','Center', ...
    'Parent',Axes, ...
    'Position',[L4(1),L4(2) + 0.1], ...
    'String','L_4');
%[]Adds a textbox to the specified axes.

text( ...
    'FontName','Arial', ...
    'FontSize',12, ...
    'FontWeight','Bold', ...
    'HorizontalAlignment','Center', ...
    'Parent',Axes, ...
    'Position',[L5(1),L5(2) - 0.1], ...
    'String','L_5');
%[]Adds a textbox to the specified axes.
end

